﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using hMailServer;

namespace MT.Mail.ServerWrap
{
    /// <summary>
    /// It is the wrapper with COM API from hMailServer
    /// </summary>
    public class HMailServer
    {
        /// <summary>
        /// Get true if the Username and Password it is correct otherwise false.
        /// </summary>
        /// <param name="userName">user account name</param>
        /// <param name="password">user account pasword</param>
        /// <returns>true/false</returns>
        public bool Authenticate(string userName, string password)
        {
            try
            {
                Application app = new hMailServer.Application();
                Account account =  app.Authenticate(userName, password);

                if (account == null)
                    return false;
                else
                    return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }



        public IMAPFolders GetFolders(string userName, string password)
        {
            try
            {

                hMailServer.Application app = new hMailServer.Application();
                hMailServer.Account account = app.Authenticate(userName, password);

                 return account.IMAPFolders;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
